home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / fileutils_3_3.lha / fileutils-3.3 / lib / system.h < prev    next >
C/C++ Source or Header  |  1992-08-01  |  6KB  |  229 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Include sys/types.h before this file.  */
  19.  
  20. #include <sys/stat.h>
  21. #ifndef S_ISREG            /* Doesn't have POSIX.1 stat stuff. */
  22. #define mode_t unsigned short
  23. #endif
  24. #if !defined(S_ISBLK) && defined(S_IFBLK)
  25. #define    S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  26. #endif
  27. #if !defined(S_ISCHR) && defined(S_IFCHR)
  28. #define    S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  29. #endif
  30. #if !defined(S_ISDIR) && defined(S_IFDIR)
  31. #define    S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  32. #endif
  33. #if !defined(S_ISREG) && defined(S_IFREG)
  34. #define    S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  35. #endif
  36. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  37. #define    S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  38. #endif
  39. #if !defined(S_ISLNK) && defined(S_IFLNK)
  40. #define    S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  41. #endif
  42. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  43. #define    S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  44. #endif
  45. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  46. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  47. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  48. #endif
  49. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  50. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  51. #endif
  52. #if !defined(HAVE_MKFIFO)
  53. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  54. #endif
  55.  
  56. #ifndef _POSIX_SOURCE
  57. #include <sys/param.h>
  58. #endif
  59.  
  60. #include "pathmax.h"
  61.  
  62. #ifndef _POSIX_VERSION
  63. off_t lseek ();
  64. #ifdef USG
  65. #include <sys/times.h>
  66. #else /* !USG */
  67. #include <sys/time.h>
  68. #endif /* !USG */
  69. #endif /* !_POSIX_VERSION */
  70.  
  71. /* Since major is a function on SVR4, we can't use `ifndef major'.  */
  72. #ifdef MAJOR_IN_MKDEV
  73. #include <sys/mkdev.h>
  74. #define HAVE_MAJOR
  75. #endif
  76. #ifdef MAJOR_IN_SYSMACROS
  77. #include <sys/sysmacros.h>
  78. #define HAVE_MAJOR
  79. #endif
  80. #ifdef major            /* Might be defined in sys/types.h.  */
  81. #define HAVE_MAJOR
  82. #endif
  83.  
  84. #ifndef HAVE_MAJOR
  85. #define major(dev)  (((dev) >> 8) & 0xff)
  86. #define minor(dev)  ((dev) & 0xff)
  87. #define makedev(maj, min)  (((maj) << 8) | (min))
  88. #endif
  89. #undef HAVE_MAJOR
  90.  
  91. #ifdef _POSIX_VERSION
  92. #include <utime.h>
  93. #else /* not _POSIX_VERSION */
  94. struct utimbuf
  95. {
  96.   long actime;
  97.   long modtime;
  98. };
  99. #endif /* _POSIX_VERSION */
  100.  
  101. #if defined(USG) || defined(STDC_HEADERS)
  102. #include <string.h>
  103. #define index strchr
  104. #define rindex strrchr
  105. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  106. #define bzero(s, n) memset ((s), 0, (n))
  107. #else /* not (USG or STDC_HEADERS) */
  108. #include <strings.h>
  109. #endif /* USG or STDC_HEADERS */
  110.  
  111. #include <errno.h>
  112. #ifdef STDC_HEADERS
  113. #define getopt system_getopt
  114. #include <stdlib.h>
  115. #undef getopt
  116. #else /* not STDC_HEADERS */
  117. char *getenv ();
  118. extern int errno;
  119. #endif /* STDC_HEADERS */
  120.  
  121. #if defined(USG) || defined(_POSIX_VERSION)
  122. #include <fcntl.h>
  123. #else /* not (USG or _POSIX_VERSION) */
  124. #include <sys/file.h>
  125. #endif /* USG or _POSIX_VERSION */
  126.  
  127. #ifndef SEEK_SET
  128. #define SEEK_SET 0
  129. #define SEEK_CUR 1
  130. #define SEEK_END 2
  131. #endif
  132. #ifndef F_OK
  133. #define F_OK 0
  134. #define X_OK 1
  135. #define W_OK 2
  136. #define R_OK 4
  137. #endif
  138.  
  139. #if defined(DIRENT) || defined(_POSIX_VERSION)
  140. #include <dirent.h>
  141. #ifdef direct
  142. #undef direct
  143. #endif
  144. #define direct dirent
  145. #define NLENGTH(direct) (strlen((direct)->d_name))
  146. #else /* not (DIRENT or _POSIX_VERSION) */
  147. #define NLENGTH(direct) ((direct)->d_namlen)
  148. #ifdef USG
  149. #ifdef SYSNDIR
  150. #include <sys/ndir.h>
  151. #else /* not SYSNDIR */
  152. #include <ndir.h>
  153. #endif /* SYSNDIR */
  154. #else /* not USG */
  155. #include <sys/dir.h>
  156. #endif /* USG */
  157. #endif /* DIRENT or _POSIX_VERSION */
  158.  
  159. #ifdef VOID_CLOSEDIR
  160. /* Fake a return value. */
  161. #define CLOSEDIR(d) (closedir (d), 0)
  162. #else
  163. #define CLOSEDIR(d) closedir (d)
  164. #endif
  165.  
  166. /* Get or fake the disk device blocksize.
  167.    Usually defined by sys/param.h (if at all).  */
  168. #ifndef DEV_BSIZE
  169. #ifdef BSIZE
  170. #define DEV_BSIZE BSIZE
  171. #else /* !BSIZE */
  172. #define DEV_BSIZE 4096
  173. #endif /* !BSIZE */
  174. #endif /* !DEV_BSIZE */
  175.  
  176. /* Extract or fake data from a `struct stat'.
  177.    ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes.
  178.    ST_NBLOCKS: Number of 512-byte blocks in the file
  179.    (including indirect blocks). */
  180. #ifndef HAVE_ST_BLOCKS
  181. # define ST_BLKSIZE(statbuf) DEV_BSIZE
  182. # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE.  */
  183. #  define ST_NBLOCKS(statbuf) (((statbuf).st_size + 512 - 1) / 512)
  184. # else /* !_POSIX_SOURCE && BSIZE */
  185. #  define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  186. # endif /* !_POSIX_SOURCE && BSIZE */
  187. #else /* HAVE_ST_BLOCKS */
  188. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  189. # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  190.                    ? (statbuf).st_blksize : DEV_BSIZE)
  191. # if defined(hpux) || defined(__hpux__)
  192. /* HP-UX counts st_blocks in 1024-byte units.
  193.    This loses when mixing HP-UX and BSD filesystems with NFS.  */
  194. #  define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 2)
  195. # else /* !hpux */
  196. #  if defined(_AIX) && defined(_I386)
  197. /* AIX PS/2 counts st_blocks in 4K units.  */
  198. #    define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 8)
  199. #  else /* not AIX PS/2 */
  200. #    define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  201. #  endif /* not AIX PS/2 */
  202. # endif /* !hpux */
  203. #endif /* HAVE_ST_BLOCKS */
  204.  
  205. /* Convert B 512-byte blocks to kilobytes if K is nonzero,
  206.    otherwise return it unchanged. */
  207. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  208.  
  209. #ifndef S_ISLNK
  210. #define lstat stat
  211. #endif
  212.  
  213. #ifndef RETSIGTYPE
  214. #define RETSIGTYPE void
  215. #endif
  216.  
  217. #ifdef __GNUC__
  218. #define alloca __builtin_alloca
  219. #else
  220. #ifdef sparc
  221. #include <alloca.h>
  222. #else
  223. #ifndef _AIX
  224. /* AIX alloca decl has to be the first thing in the file, bletch! */
  225. char *alloca ();
  226. #endif
  227. #endif
  228. #endif
  229.